// 04myCenter/08bizAuth/01enterpriseAuth/01enterpriseAuth.js
var co = require('../../../resource/js/common.js')
var app = getApp()
var _this, _data,_opt
//var Biz_ID = ''

Page({
   data: {
      bizInfo:'',//企业信息
      //是否显示弹窗
      popMenuIsShow: false,
      //营业执照认证
      isCertAuth: 0,
      //法人微信认证
      isLegalPersonAuth: 0,
      //法人银行卡认证
      isBankCardAuth: 0,
   },

   onLoad: function (opt) {
      _this = this
      _data = this.data
      _opt = opt
      console.log('opt==', _opt)
      //Biz_ID = opt.Biz_ID
      this.getBizInfo()
      
      console.log('isCertAuth==', _data.isCertAuth)
      console.log('isLegalPersonAuth==', _data.isLegalPersonAuth)
      console.log('isBankCardAuth==', _data.isBankCardAuth)

      //console.log('Biz_ID==', Biz_ID)
     
   },
   //获取商家信息
   getBizInfo:function(){
      var url = 'jyhs/Admin/getInfo'
      co.getShareApi(url,{
         Biz_ID:_opt.Biz_ID
      },function(res){
         console.log('res1==',res)
         if(res.code == 0){
            _this.setData({
               bizInfo:res.data,
               isCertAuth: res.data.Is_Auth,
               isLegalPersonAuth: res.data.Legal_Person_User_ID,
               isBankCardAuth: res.data.BankCard_Is_Auth
            })
         }else{
            co.toastAllText(res.msg)
         }
      })
   },


   onUnload: function () {
      //Biz_ID = ''
   },

   onShow: function () {
      console.log('OPT',_opt)
      // app.getShopInfo(function (res) {
      //    console.log('Is_Auth==', app.Data.shopInfo.Is_Auth)
      //    _this.setData({
      //       isCertAuth: app.Data.shopInfo.Is_Auth,
      //       isLegalPersonAuth: app.Data.shopInfo.Legal_Person_User_ID,
      //       isBankCardAuth: app.Data.shopInfo.BankCard_Is_Auth
      //    })
      // })
   },

   onHide: function () {
      _this.setData({
         popMenuIsShow: false
      });
   },

   //现实弹窗
   showPopMenu: function () {
      if (_data.isCertAuth === 0) {
         _this.setData({
            popMenuIsShow: !_data.popMenuIsShow
         });
      }
      else if (_data.isCertAuth === 1) {
         _this.gotoQuickAuth()
      }
      else if (_data.isCertAuth === 2) {
         _this.gotoCertAuth()
      }
      else {
         co.toastAllText('正在审核中...')
      }
   },

   //营业执照认证
   gotoCertAuth: function () {
      wx.navigateTo({
         url: '/04myCenter/08bizAuth/01enterpriseAuth/certAuth/certAuth?Biz_ID=' + _opt.Biz_ID,
      })
   },

   //快捷认证
   gotoQuickAuth: function () {
      wx.navigateTo({
         url: '/04myCenter/08bizAuth/01enterpriseAuth/certAuth/quickAuth?Biz_ID='+_opt.Biz_ID,
      })
   },

   //法人微信认证
   gotoLegalPersonAuth: function () {
      if (!_data.isCertAuth) {
         co.toastAllText('证件需要先认证!')
         return
      }

      if (_data.isLegalPersonAuth) {
         co.toastAllText('已经认证!')
         return
      }

      wx.navigateTo({
         //url: '/03admin/12bizAuth/legalPersonAuth/legalPersonAuth',
         //url: '/03admin/09getMoney/03bankCard/01addBankCard/addBankCard'
         url: '/04myCenter/08bizAuth/01enterpriseAuth/whcatAuth/whcatAuth?Biz_ID='+_opt.Biz_ID
      })
   },

   //法人银行卡认证
   gotoBankAuth: function () {
      if (!_data.isCertAuth) {
         co.toastAllText('证件需要先认证!')
         return
      }

      if (!_data.isLegalPersonAuth) {
         co.toastAllText('法人需要先认证!')
         return
      }

      if (_data.isBankCardAuth) {
         co.toastAllText('已经认证!')
         return
      }

      wx.navigateTo({
         url: '/04myCenter/01myWallet/01myChange/bankCard/addBankCard/addBankCard?scene=From_Page.bizAuth'
      })
   },

})